package com.df.springmvc.common.dao;

import java.util.ArrayList;
import java.util.HashMap;
import org.springframework.stereotype.Repository;
import com.common.bean.SQLInsertBean;
import com.common.bean.SQLResultBean;
import com.df.springmvc.supper.SupperDao;

/**
 * 本类只做数据库操作处理
 * @author David
 */
@Repository
public class FileDao extends SupperDao{
	String table="s_file_info";
	
	public Object add(HashMap<String,Object> map) throws Exception{
		SQLInsertBean bean=new SQLInsertBean(table,map);
		return excuteSqlBean(bean);
	}
	public HashMap<String,Object> query(String fileId) throws Exception{
		String sql="select fileName,fileContent from " + table + " where fileId=?";
		SQLResultBean resultBean=querySqlToSQLResultBean(sql,new Object[]{fileId});
		ArrayList<HashMap<String,Object>> mapList=resultBean.getMapList();
		if(mapList.size() == 0){
			org.apache.log4j.Logger.getLogger(getClass()).info("找不到文件");
			throw new Exception("数据库不存在");
		}else{
			HashMap<String,Object> object=mapList.get(0);
			return object;
		}
	}
	public ArrayList<HashMap<String,Object>> getFileList(String fileGroupId) throws Exception{
		// TODO Auto-generated method stub
		String sql="select guid,fileId,fileName,fileRoute,fileSize,fileAuthor,fileType from " + table + " where fileGroupId=? and fileGroupId != 'null' ";
		SQLResultBean resultBean=querySqlToSQLResultBean(sql,new Object[]{fileGroupId});
		ArrayList<HashMap<String,Object>> mapList=resultBean.getMapList();
		return mapList;
	}
	@Override
	public Object del(HashMap<String,Object> map) throws Exception{
		Object fileId=map.get("fileId");
		// TODO Auto-generated method stub
		String sql="delete from " + table + " where fileId=? ";
		updateSql(sql,new Object[]{fileId});
		return super.del(map);
	}
}
